const express = require("express");
const userRouter = express.Router();
const userServer = require("../../server/admin/userServer");
const sendMsg = require("../reqSendResult");
// 获取用户列表
userRouter.get(
	"/",
	sendMsg.asyncHandler(async (req, res) => {
		console.log(req.query);
		return await userServer.getUser(
			req.query.current,
			req.query.pageSize,
			req.query.keyword,
      req.query.status
		);
	})
);
// 添加用户
userRouter.post(
	"/addUser",
	sendMsg.asyncHandler(async (req, res) => {
		return await userServer.addUser(req.body);
	}, "添加用户成功")
);
// 修改用户
userRouter.put(
	"/updateUser",
	sendMsg.asyncHandler(async (req, res) => {
		return await userServer.updateUser(req.body.id, req.body);
	}, "修改用户成功")
);
// 修改用户状态
userRouter.patch(
	"/updateUserStatus",
	sendMsg.asyncHandler(async (req, res) => {
		return await userServer.updateUserStatus(req.body.id, req.body.userState);
	}, "修改用户状态成功")
);
// 获取用户详情
userRouter.get(
	"/getUserInfo",
	sendMsg.asyncHandler(async (req, res) => {
		return await userServer.getUserInfo(req.query.id);
	})
);
// 删除用户
userRouter.delete(
	"/deleteUser",
	sendMsg.asyncHandler(async (req, res) => {
		return await userServer.deleteUser(req.query.id);
	}, "删除用户成功")
);

module.exports = userRouter;
